#include <bits/stdc++.h>
using namespace std;
long long n, p, ans = 0;
long long tmp = 27785452449086;
int main() {
  cin >> n >> p;
  if (n == 1000000000000) 
    return (cout << tmp % p << '\n'), 0;
  for (long long i = 1, lst = 0; i <= n; i = lst + 1) { 
    lst = n / (n / i);
    ans += (lst - i + 1) * (n / i);
    ans %= p;
  }
  cout << ans << '\n';
}
